import React from 'react'
import { Toast } from 'antd-mobile';
import { reqCartadd } from '../../request/api';

import './list.css'
export default function List(props) {
    let toDetail = (id) =>{
        console.log(props);
        
        props.history.push("/detail/id="+id)
    }

    let addCate = (e,id)=>{
        e.stopPropagation()
        reqCartadd(id).then(res=>{
            if(res.code === 200){
                Toast.info(res.msg,1,()=>{},false)
            }
        })
    }
    return (
        <div className="goodsL_box" >
            {
                props.arr.map(item=>{
                    return <div className="goodslist_wrap" key={item.id} onClick={()=>toDetail(item.id)}>
                    <div className="list_l">
                        <img src={item.img} alt="" />
                    </div>
                    <div className="list_r">
                        <div className="list_title">
                            <span>限时</span>{item.goodsname}
                        </div>
                        <div className="list_b">
                            <div className="list_r_t">
                                <div className="list_price">
                                    <span>￥{item.price}</span>
                                    <del>￥{item.market_price}</del>
                                </div>
                                <div className="list_r_b">
                                    {item.description}
                                </div>
                            </div>
                            <div className="list_btn"><span className="list_btn_span" onClick={(e)=>addCate(e,item.id)}>加入购物车</span></div>
                        </div>
                        
                    </div>
                </div>
                })
            }
        </div>
    )
}
